//-----------------------------------------------------------------------
// <copyright file="Continue.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
// </copyright>
// <summary>Causes a WebSite that was Paused to Continue.</summary>
//-----------------------------------------------------------------------
namespace Microsoft.Sdc.Tasks.Web.WebSite
{
    using System;

    /// <summary>
    /// Continues a paused web site
    /// </summary>
    /// <remarks>
    /// <code><![CDATA[<Web.WebSite.Continue
    ///     (Description="description" || Identifier="identifier"/>]]></code>
    /// <para>where:</para>
    /// <para><i>Description</i></para>
    /// <para>Web site description to continue</para>
    /// <para><i>Identifier</i></para>
    /// <para>Web site identifier to continue</para>
    /// <para><b>Either a <i>description</i> or an <i>identifier</i> must be specified.</b></para>
    /// </remarks>
    /// <example>
    /// <code><![CDATA[
    /// <Project>
    ///     <Target Name="Test" >
    ///         <Web.WebSite.Continue Desciption="mytestsite" />
    ///     </Target>
    /// </Project>
    /// ]]></code>    
    /// </example>    
    public class Continue : TaskBase
    {
        private string description;
        private string identifier;
        private string machineName = "localhost";

        /// <summary>
        /// Machine to operate on
        /// </summary>
        public string MachineName
        {
            get { return this.machineName; }
            set { this.machineName = value; }
        }

        /// <summary>
        /// Description of web site to continue.
        /// </summary>
        /// <value>A valid web site description</value>
        /// <remarks>If this parameter is not specified you must specify the site <seealso cref="Identifier">Identifier</seealso> 
        /// for the site you wish to apply the binding to</remarks>
        public string Description
        {
            get { return (this.description ?? String.Empty); }
            set { this.description = value; }
        }

        /// <summary>
        /// Identifier for the web site to continue.
        /// </summary>
        /// <value>A valid web site identifier</value>
        /// <remarks>If this parameter is not specified you must specify the site <seealso cref="Description">Description</seealso> 
        /// for the site you wish to delete</remarks>
        public string Identifier
        {
            get { return (this.identifier ?? String.Empty); }
            set { this.identifier = value; }
        }

        /// <summary>
        /// Performs the action of this task.
        /// </summary>
        protected override void InternalExecute()
        {
            int id = this.Utilities.CheckWebSiteDescriptionOrIdentifier(this.description, this.identifier, "Continuing", this.MachineName);
            if (Microsoft.Sdc.Tasks.Configuration.Web.WebSite.Exists(this.MachineName, id))
            {
                Microsoft.Sdc.Tasks.Configuration.Web.WebSite web = Microsoft.Sdc.Tasks.Configuration.Web.WebSite.Load(this.MachineName, id);
                web.Continue();
            }
        }
    }
}